package com.dev.web.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dev.bbs.domain.BbsComment;
import com.dev.bbs.service.IBbsCommentService;
import com.dev.common.annotation.Log;
import com.dev.common.core.controller.BaseController;
import com.dev.common.core.domain.AjaxResult;
import com.dev.common.core.page.TableDataInfo;
import com.dev.common.enums.BusinessType;
import com.dev.common.utils.poi.ExcelUtil;

/**
 * 帖子评论Controller
 *
 * @author dev
 * @date 2019-09-23
 */
@Controller
@RequestMapping("/bbs/comment")
public class BbsCommentController extends BaseController
{
    private String             prefix = "bbs/comment";

    @Autowired
    private IBbsCommentService bbsCommentService;

    @RequiresPermissions("bbs:comment:view")
    @GetMapping()
    public String comment()
    {
        return prefix + "/comment";
    }

    /**
    * 查询帖子评论列表
    */
    @RequiresPermissions("bbs:comment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BbsComment bbsComment)
    {
        startPage();
        List<BbsComment> list = bbsCommentService.selectBbsCommentList(bbsComment);
        return getDataTable(list);
    }

    /**
     * 导出帖子评论列表
     */
    @RequiresPermissions("bbs:comment:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BbsComment bbsComment)
    {
        List<BbsComment> list = bbsCommentService.selectBbsCommentList(bbsComment);
        ExcelUtil<BbsComment> util = new ExcelUtil<BbsComment>(BbsComment.class);
        return util.exportExcel(list, "comment");
    }

    /**
    * 新增帖子评论
    */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存帖子评论
     */
    @RequiresPermissions("bbs:comment:add")
    @Log(title = "帖子评论", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BbsComment bbsComment)
    {
        return toAjax(bbsCommentService.insertBbsComment(bbsComment));
    }

    /**
     * 修改帖子评论
     */
    @GetMapping("/edit/{mentId}")
    public String edit(@PathVariable("mentId") Long mentId, ModelMap mmap)
    {
        BbsComment bbsComment = bbsCommentService.selectBbsCommentById(mentId);
        mmap.put("bbsComment", bbsComment);
        return prefix + "/edit";
    }

    /**
     * 修改保存帖子评论
     */
    @RequiresPermissions("bbs:comment:edit")
    @Log(title = "帖子评论", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BbsComment bbsComment)
    {
        return toAjax(bbsCommentService.updateBbsComment(bbsComment));
    }

    /**
    * 删除帖子评论
    */
    @RequiresPermissions("bbs:comment:remove")
    @Log(title = "帖子评论", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bbsCommentService.deleteBbsCommentByIds(ids));
    }
}
